package com.kasax.android.arch.base.mvp;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;

import com.kasax.android.arch.utils.LogUtils;

import java.lang.ref.WeakReference;

public class BasePresenter<T extends IBaseView> implements LifecycleObserver {
    protected WeakReference<T> viewRef;

    /**
     * 绑定view
     *
     * @param view
     */
    public void attachView(T view) {
        viewRef = new WeakReference<>(view);
    }

    /**
     * 解除绑定
     */
    public void detachView() {
        if (viewRef != null && viewRef.get() != null) {
            viewRef.clear();
            viewRef = null;
        }
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    void onCreateX(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onCreateX");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    void onStartX(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onStartX");
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    void onStop(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onStop");
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    void onResume(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onResume");
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    void onPause(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onPause");
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    void onDestory(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onDestory");
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
    void onAny(LifecycleOwner owner) {
        // LogUtils.e("BasePresenter onAny");
    }

}
